
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                               clock.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                                    Forrest Yu, 2005
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#include "type.h"
#include "const.h"
#include "protect.h"
//#include "proto.h"
#include "string.h"
#include "proc.h"
#include "proto.h"
#include "global.h"


/*======================================================================*
                           clock_handler
 *======================================================================*/
PUBLIC void clock_handler(int irq)
{
	ticks++;
	p_proc_ready->ticks--;
	
	PROCESS*	p = proc_table;

	for(int i=0;i<NR_TASKS;i++, p++){
		if(p->sleep_ticks > 0){ // 睡眠
			p->sleep_ticks--;
		}
		
		if(p->ticks == 0){ // 睡醒了，恢复活力。
			p->ticks = p->real_ticks;
		}

	}

	schedule();
}

/*======================================================================*
                              milli_delay
 *======================================================================*/
PUBLIC void milli_delay(int milli_sec)
{
        int t = get_ticks();

        while(((get_ticks() - t) * 1000 / HZ) < milli_sec) {}
}

